$(function() {
    $('#appost_add').click(function() {
        appost_id += 1;
        appost_text = '<tr id="appost_'+ appost_id +'"><th scope="row"><label for="appost_old_'+ appost_id +'">'+ appost_title + ' ' + appost_id +'</label></th>';
        appost_text += '<td><input type="text" id="appost_old_'+ appost_id +'" name="appost_old[]" /></td>';
        appost_text += '<td><input type="text" id="appost_new_'+ appost_id +'" name="appost_new[]" /></td></tr>';
        $('#append-table').append(appost_text);
    });

    $('#appost_del').click(function(){
        $('#appost_'+ appost_id ).remove();
        if(appost_id>0){
            appost_id--;
        }
    });

    $('#append').click(function(){
        postAppend();
    });
    
});

function ajax(opt){
    /* opt = {
        u: url, -- blogURL
        m: method, -- get
        d: data, -- null
        dt: dataType, -- html
        b: beforeSend,
        e: error,
        s: success
        fn: 'function'
    }; */
    
    url = opt.u ? opt.u : vxorURL;
    if(opt.fn){
        url += '&action='+opt.fn;
    }
    type = opt.m ? opt.m : 'GET';
    data = opt.d ? opt.d : null;
    dataType = opt.dt ? opt.dt : 'html';
    beforeSend = opt.b ? opt.b : null;
    error = opt.e ? opt.e : function(){
        alert(lang.commonError);
        document.body.style.cursor = 'auto';
    };
    success = opt.s ? opt.s : function(d){
        alert(d)
    };
    $.ajax( {
        url : url,
        type : type,
        data : data,
        dataType : dataType,
        beforeSend : beforeSend,
        error : error,
        success : success
    });
    
}

function postAppend(){
    var form = $('#appendform');
    var url =  vxorURL;
    var fn = 'append';
    var data = form.serialize();

    var beforeSend = function(){
        //TODO
    };

    var error = function(){
        //TODO
    };

    var success = function(result){
        //TODO
    };

    ajax({
        u: url,
        m: 'POST',
        d: data,
        b: beforeSend,
        e: error,
        s: success,
        f: fn
    });

}
